package com.lj.auth.config;

import cn.dev33.satoken.stp.StpInterface;
import com.lj.sys.result.LoginUserInfo;
import com.lj.sys.utils.SysUserUtils;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

/**
 * @author luojing
 * @since 2024/11/8 17:17
 * Sa-token 的权限认证实现
 */
@Component
public class StpInterfaceImpl implements StpInterface {

    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        LoginUserInfo userInfo = SysUserUtils.getUserInfo();
        if (userInfo.isSuperAdmin()) {
            // 超管拥有所有权限
            return Collections.singletonList("*");
        }
        return userInfo.getPermissionList();
    }

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        LoginUserInfo userInfo = SysUserUtils.getUserInfo();
        if (userInfo.isSuperAdmin()) {
            // 超管拥有所有权限
            return Collections.singletonList("*");
        }
        return userInfo.getRoleCodeList();
    }
}
